{extend name="index/public" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        {MyTag:client name="client" /}
    </div>
    <div class="layui-inline">
        <select name="plat" id="plat" lay-filter="plat">
            <option value="">全部（渠道类型）</option>
            <option value="cps">CPS</option>
            <option value="sdk">联运</option>
        </select>
    </div>
    <div class="layui-inline">
        <input type="text" name="date" value="{$date}" id="date" lay-verify="datetime" placeholder="支付时间" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-inline" style="width: 125px;">
        <input type="text" class="layui-input layui-disabled" value="{$date2}" id="date2" placeholder=" - ">
    </div>
    <div class="layui-inline">
        <select name="debug" id="debug" lay-filter="debug">
            <option value="">全部（测试数据）</option>
            <option value="1">测试数据</option>
            <option value="2" selected>非测试数据</option>
        </select>
    </div>
    <div class="layui-inline">
        <select name="game_result" id="game_result" lay-filter="game_result">
            <option value="">全部（游戏通知）</option>
            <option value="1">游戏到账</option>
            <option value="2">游戏未到账</option>
        </select>
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:channel type='manage' /}
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:game type='manage' /}
        </div>
    </div>
    <div class="layui-inline">
        <input type="text" name="server_id" value="" id="server_id" placeholder="区服ID/区服名称" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-inline">
        <select name="pay_type" id="pay_type" lay-filter="pay_type">
            <option value="">全部（支付方式）</option>
            <option value="wxpay">CPS微信</option>
            <option value="alipay">CPS支付宝</option>
        </select>
    </div>
    <div class="layui-inline" style="width: auto;">
        <div class="my-btn my-btn-total">充值总额：<span id="total_price">0.00</span></div>
    </div>
    <div class="layui-inline">
        <a href="javascript:;" class="layui-btn my-btn-sm my-btn" id="toolBtn">导出</a>
        <button class="layui-btn searchBtn my-btn my-btn-sm" lay-filter="demo1" lay-submit="">搜索</button>
    </div>
</form>
<table id="tableBox" lay-filter="tableBox"></table>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use(['form', 'laydate', 'table'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,laydate = layui.laydate
            ,load = null
            ,active = {
                reload: function () {
                    var jsonObj = {
                        "plat": $('#plat').val()
                        ,"date": $('#date').hasClass('layui-disabled') ? $('#date2').val() : $('#date').val()
                        ,"debug": $('#debug').val()
                        ,"game_result": $('#game_result').val()
                        ,"channel_id": $('#channel_id').val()
                        ,"game_id": $('#game_id').val()
                        ,"server_id": $('#server_id').val()
                        ,"pay_type": $('#pay_type').val()
                        ,"game_server": $('#game_server').find('.my-btn').attr('val')
                        ,"game_publish": $('#game_publish').find('.my-btn').attr('val')
                        ,"game_platform": $('#game_platform').find('.my-btn').attr('val')
                        ,"game_client": $('#game_client').find('.my-btn').attr('val')
                    };

                    table.reload('tableId', {
                        page: {curr: 1}
                        ,where: jsonObj
                        ,height: 'full-145'
                    })
                },
            };

        table.render({
            elem: '#tableBox'
            ,height: 'full-145'
            ,url: '{:url("PayOrder/index")}'
            ,where: {date:$('#date').val(), debug:$('#debug').val()}
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function (res, curr, count) {
                $('#total_price').html(res.params);
                layer.close(load);
                $('#layui-loading').hide();
            }
            ,cols: [[
                {field:'my_order_id', title: '米娱订单号', width: 170}
                ,{field:'pay_time', title: '支付时间', width: 150, sort:true}
                ,{field:'type', title: '类型', width: 60}
                ,{field:'game_id', title: '充值游戏', width: 150}
                ,{field:'server_id', title: '区服名称', width: 150}
                ,{field:'reg_cps_id', title: '充值渠道' , width: 150}
                ,{field:'total_price', title: '充值金额', width: 100, sort:true}
                ,{field:'cp_order_id', title: 'CP订单号', width: 150, sort:true}
                ,{field:'ch_order_id', title: '渠道订单号', width: 150, sort:true}
                ,{field:'product_name', title: '产品名称', width: 120, sort:true}
                ,{field:'pay_type', title: '支付方式', width: 100, sort:true}
                ,{field:'pay_order_id', title: '支付单号', width: 150, sort:true}
            ]]
        });

        //日期
        laydate.render({
            elem: '#date'
            ,type: 'date'
            ,range: true
            ,calendar: true
            ,min: '2016-01-01'
            ,max: 0
            ,ready: function(date){
                $('#date2').addClass('layui-disabled');
                $('#date').removeClass('layui-disabled');
            }
        });

        laydate.render({
            elem: '#date2'
            ,type: 'month'
            ,range: true
            ,min: '2016-01-01'
            ,max: 0
            ,format: 'yyyy-MM'
            ,ready: function(date){
                $('#date').addClass('layui-disabled');
                $('#date2').removeClass('layui-disabled');
            }
        });

        $('#searchBox .searchBtn').on('click', function(){
            load = layer.load();
            active['reload'].call(this);
            return false;
        });

        $('#toolBtn').on('click', function() {
            var jsonStr = ''
                , jsonObj = {
                "plat": $('#plat').val()
                , "date": $('#date').hasClass('layui-disabled') ? $('#date2').val() : $('#date').val()
                , "debug": $('#debug').val()
                , "game_result": $('#game_result').val()
                , "channel_id": $('#channel_id').val()
                , "game_id": $('#game_id').val()
                , "server_id": $('#server_id').val()
                , "pay_type": $('#pay_type').val()
                , "game_server": $('#game_server').find('.my-btn').attr('val')
                , "game_publish": $('#game_publish').find('.my-btn').attr('val')
                , "game_platform": $('#game_platform').find('.my-btn').attr('val')
                , "game_client": $('#game_client').find('.my-btn').attr('val')
                , "export": true
            };
            layer.msg('导出中....', {icon: 1, time: 2000});
            for (k in jsonObj) {
                jsonStr += k + '=' + jsonObj[k] + '&';
            }
            window.location.href = '{:url("PayOrder/index")}?' + jsonStr.substring(0, jsonStr.length - 1);
            return false;
        });
    });
</script>
{/block}